package com.demo.sharding.controller;

import com.demo.sharding.entity.User;
import com.demo.sharding.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * @Author: WuPeng
 * @Date: 2021/5/28 3:13 下午
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    private UserMapper userMapper;

    @RequestMapping("save")
    public String save(String name, Integer age){
        User user = new User();
        user.setName(name);
        user.setAge(age);
        userMapper.insert(user);
        return "SUCCESS";
    }

    @GetMapping("select")
    public Object select(Long id){
        User user = userMapper.selectById(id);
        return user;
    }

}
